#include <iostream>
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>




/* // 输出型参数获取ID
void *newthreadrun(void *args)
{
    return nullptr;
}
int main()
{
    pthread_t tid;
    pthread_create(&tid, nullptr, newthreadrun, nullptr);

    std::cout << "I am new thread,pthread_t : " << tid << std::endl;
    sleep(2);

    return 0;
}
*/


/* // pthread_self
void *newthreadrun(void *args)
{
    while (true)
    {
        std::cout << "I am new thread,pthread_t : " << pthread_self() << std::endl;
        sleep(1);
    }
}
int main()
{
    pthread_t tid;
    pthread_create(&tid, nullptr, newthreadrun, nullptr);

    while (true)
    {
        std::cout << "I am main thread,pthread_t : " << pthread_self() << std::endl;
        sleep(1);
    }
    return 0;
}
*/

/*  // 创建线程
void *newthreadrun(void *args)
{
    while (true)
    {
        std::cout << "I am new thread,pid : " << getpid() << std::endl;
        sleep(1);
    }
}
int main()
{
    pthread_t tid;
    pthread_create(&tid, nullptr, newthreadrun, nullptr);

    // 新和主两个线程，谁先运行呢？不确定，由调度器决定
    while (true)
    {
        std::cout << "I am main thread,pid : " << getpid() << std::endl;
        sleep(1);
    }
    return 0;
}
*/